﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.Serialization;

[XmlRoot("cashflow")]
public class CashFlow
{
	public CashFlow()
	{
	}

	private double _cash = 0.0;
	[XmlElement("cash")]
	public double Cash { get { return _cash; } set { _cash = value; } }

	public static CashFlow GetCashFlow()
	{
		string path = HttpContext.Current.Server.MapPath("/xml/cashflow.xml");
		XmlSerializer serializer = new XmlSerializer(Type.GetType("CashFlow"));

		XmlReader reader = XmlReader.Create(path);
		reader.Read();

		CashFlow cashflow = (CashFlow)serializer.Deserialize(reader);
		reader.Close();
		return cashflow;
	}

	public void Save()
	{
		string path = HttpContext.Current.Server.MapPath("/xml/cashflow.xml");
		XmlSerializer serializer = new XmlSerializer(Type.GetType("CashFlow"));

		XmlWriterSettings settings = new XmlWriterSettings();
		settings.Encoding = Encoding.Unicode;
		settings.Indent = true;
		settings.IndentChars = "    ";

		XmlWriter writer = XmlWriter.Create(path, settings);

		serializer.Serialize(writer, this);
		writer.Close();
	}
}